package cn.stylefeng.guns.modular.ctm.dto;

import cn.stylefeng.guns.modular.api.enums.*;
import cn.stylefeng.guns.modular.ctm.entity.EnterPrise;
import cn.stylefeng.guns.modular.ctm.entity.UserInfo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import java.util.Arrays;
import java.util.Optional;

@Setter
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "岗位信息")
public class CtmDTO  extends Model<CtmDTO> {
    private static final long serialVersionUID = 1L;

    /**
     * 岗位id（该值用作判断更新还是新增）
     */
    @TableId
    @NotBlank(message = "岗位id不能为空")
    private String inputJobId;
    /**
     * 岗位名称
     */
    @NotBlank(message = "岗位名称不能为空")
    private String jobName;
    /**
     * 工种代码值，具体值见5.14
     */
    @NotBlank(message = "工种代码值不能为空")
    private String work;
    /**
     * 详细工作地址
     */
    @NotBlank(message = "详细工作地址不能为空")
    private String workPlaceDetail;
    /**
     * 工作地区编码，具体值见5.13
     */
    @NotBlank(message = "工作地区编码不能为空")
    private String workTown;
    /**
     * 最高薪资,不能与具体薪资同时为空
     */
    private Long maxSalary;
    /**
     * 最低薪资,不能与具体薪资同时为空
     */
    private Long minSalary;
    /**
     * 具体薪资,不能与最高最低薪资同时为空
     */
    private Long salary;
    /**
     * 招聘人数
     */
    @NotBlank(message = "招聘人数不能为空")
    private Long numOfMember;
    /**
     * 性别限制,具体值见5.6
     */
    private String genderLimitations;
    /**
     * 岗位发布状态，具体值见5.4
     */
    @NotBlank(message = "岗位发布状态不能为空")
    private String postStatus;
    /**
     * 结算方式,具体值看代码表,默认填写bymonth
     */
    @NotBlank(message = "结算方式不能为空")
    private String paymentMethod;
    /**
     * 学历要求,具体值见5.2
     */
    private String educationLevel;
    /**
     * 工作方式,具体值见5.5
     */
    @NotBlank(message = "工作方式不能为空")
    private String workMode;
    /**
     * 招聘人最大年龄
     */
    private Long maximumAge;
    /**
     * 招聘人最小年龄
     */
    private Long minimumAge;
    /**
     * 岗位发布开始时间,格式yyyy-MM-dd
     */
    private String startTime;
    /**
     * 岗位发布结束时间,格式yyyy-MM-dd
     */
    private String endTime;
    /**
     * 岗位创建时间,格式yyyy-MM-dd
     */
    private String createTime;
    /**
     * 优先级,具体值见5.1
     */
    private String priority;
    /**
     * 岗位工作内容
     */
    private String workContent;
    /**
     * 岗位工作时间,例9:00-18:00
     */
    private String workTimeDetail;
    /**
     * 工作时间段,具体值见5.7
     */
    private String workTime;
    /**
     * 工作日期始,短期兼职岗位必传,格式yyyy-MM-dd
     */
    private String workDateStart;
    /**
     * 工作日期止,短期兼职岗位必传,格式yyyy-MM-dd
     */
    private String workDateEnd;
    /**
     * 招聘类型,具体值见5.8
     */
    @NotBlank(message = "招聘类型不能为空")
    private String recruitmentType;
    /**
     * 岗位福利,具体值见5.9
     */
    private String welfareRequirement;
    /**
     * 岗位描述
     */
    private String jobDescribe;
    /**
     * 岗位标题
     */
    private String jobTitle;
    /**
     * 备注
     */
    private String remark;
    /**
     * 薪资单位,具体值见5.10,无则默认填写bymonth
     */
    @NotBlank(message = "薪资单位不能为空")
    private String salaryCalculation;
    /**
     * 联系号码
     */
    @NotBlank(message = "联系号码不能为空")
    private String cellPhone;
    /**
     * 身高要求
     */
    private String higher;
    /**
     * 是否允许经纪人带队报名,0不允许,1允许
     */
    private String allowLaborApply;
    /**
     * 长期兼职工作日期，招聘类型为长期兼职时必传,具体值看代码表
     */
    private String longTimeWorkDate;
    /**
     * 岗位来源（平台名称）
     */
    @NotBlank(message = "岗位来源不能为空")
    private String gwly;
    /**
     * 岗位来源地址（原链接地址）
     */
    @NotBlank(message = "岗位来源地址不能为空")
    private String gwlyUrl;
    /**
     * 岗位适合人群具体值见5.15
     */
    @NotBlank(message = "岗位适合人群不能为空")
    private String suitablePeople;
    /**
     * 岗位标签具体值见5.16（可多选，多个用逗号隔开）
     */
    @NotBlank(message = "岗位标签不能为空")
    private String jobTag;
    /**
     * 岗位下线时间,格式yyyy-MM-dd
     */
    @NotBlank(message = "岗位下线时间不能为空")
    private String cronDate;
    /**
     * 工作地址经度
     */
    private String lng;
    /**
     * 工作地址纬度
     */
    private String lat;
    /**
     * 是否收藏
     */
    private String collectOrNot;
    /**
     * 不感兴趣
     */
    private String notInterested;
    /**
     * 发布人用户对象（为空传空对象）
     */
    @TableField(exist = false)
    private UserInfo userInfo = new UserInfo();
    /**
     * 招聘企业信息
     */
    @TableField(exist = false)
    @NotBlank(message = "招聘企业信息不能为空")
    private EnterPrise enterPrise = new EnterPrise();

    public String getInputJobId() {
        return inputJobId;
    }

    public String getJobName() {
        return jobName;
    }

    public String getWorkPlaceDetail() {
        return workPlaceDetail;
    }

    public String getWork() {
        Optional<String> value = Arrays.stream(WorkEnum.values())
                .filter(workEnum -> StringUtils.equals(workEnum.getCode(), work))
                .map(WorkEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> work);
    }

    public String getWorkTown() {
        Optional<String> value = Arrays.stream(WorkTownEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), workTown))
                .map(WorkTownEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> workTown);
    }

    public Long getMaxSalary() {
        return maxSalary;
    }

    public Long getMinSalary() {
        return minSalary;
    }

    public Long getSalary() {
        return salary;
    }

    public Long getNumOfMember() {
        return numOfMember;
    }

    public String getGenderLimitations() {
        Optional<String> value = Arrays.stream(GenderLimitationsEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), genderLimitations))
                .map(GenderLimitationsEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> genderLimitations);
    }

    public String getPostStatus() {
        Optional<String> value = Arrays.stream(PostStatusEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), postStatus))
                .map(PostStatusEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> postStatus);
    }

    public String getPaymentMethod() {
        Optional<String> value = Arrays.stream(PaymentMethodEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), paymentMethod))
                .map(PaymentMethodEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> paymentMethod);
    }

    public String getEducationLevel() {
        Optional<String> value = Arrays.stream(EducationLevelEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), educationLevel))
                .map(EducationLevelEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> educationLevel);
    }

    public String getWorkMode() {
        Optional<String> value = Arrays.stream(WorkModeEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), workMode))
                .map(WorkModeEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> workMode);
    }

    public Long getMaximumAge() {
        return maximumAge;
    }

    public Long getMinimumAge() {
        return minimumAge;
    }

    public String getStartTime() {
        return startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public String getCreateTime() {
        return createTime;
    }

    public String getPriority() {
        Optional<String> value = Arrays.stream(PriorityEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), priority))
                .map(PriorityEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> priority);
    }

    public String getWorkContent() {
        return workContent;
    }

    public String getWorkTimeDetail() {
        return workTimeDetail;
    }

    public String getWorkTime() {
        Optional<String> value = Arrays.stream(WorkTimeEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), workTime))
                .map(WorkTimeEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> workTime);
    }

    public String getWorkDateStart() {
        return workDateStart;
    }

    public String getWorkDateEnd() {
        return workDateEnd;
    }

    public String getRecruitmentType() {
        Optional<String> value = Arrays.stream(RecruitmentTypeEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), recruitmentType))
                .map(RecruitmentTypeEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> recruitmentType);
    }

    public String getWelfareRequirement() {
        Optional<String> value = Arrays.stream(WelfareRequirementEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), welfareRequirement))
                .map(WelfareRequirementEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> welfareRequirement);
    }

    public String getJobDescribe() {
        return jobDescribe;
    }

    public String getJobTitle() {
        return jobTitle;
    }

    public String getRemark() {
        return remark;
    }

    public String getSalaryCalculation() {
        Optional<String> value = Arrays.stream(SalaryCalculationEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), salaryCalculation))
                .map(SalaryCalculationEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> salaryCalculation);
    }

    public String getCellPhone() {
        return cellPhone;
    }

    public String getHigher() {
        return higher;
    }

    public String getAllowLaborApply() {
        if (StringUtils.equals("0", allowLaborApply)) {
            return "不允许";
        } else if (StringUtils.equals("1", allowLaborApply)) {
            return "允许";
        }
        return allowLaborApply;
    }

    public String getLongTimeWorkDate() {
        Optional<String> value = Arrays.stream(LongTimeWorkDateEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), longTimeWorkDate))
                .map(LongTimeWorkDateEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> longTimeWorkDate);
    }

    public String getGwly() {
        return gwly;
    }

    public String getGwlyUrl() {
        return gwlyUrl;
    }

    public String getSuitablePeople() {
        Optional<String> value = Arrays.stream(SuitablePeopleEnum.values())
                .filter(enums -> StringUtils.equals(enums.getCode(), suitablePeople))
                .map(SuitablePeopleEnum::getValue)
                .findFirst();
        return value.orElseGet(() -> suitablePeople);
    }

    public String getJobTag() {
        StringBuilder jobTagList = new StringBuilder();
        for (JobTagEnum enums : JobTagEnum.values()) {
            String[] split = jobTag.split(",");
            for (String s : split) {
                if (StringUtils.equals(s, enums.getCode())) {
                    jobTagList.append(enums.getValue()).append(",");
                }
            }
        }
        return jobTagList.substring(0, jobTagList.length() - 1);
    }

    public String getCronDate() {
        return cronDate;
    }

    public String getLng() {
        return lng;
    }

    public String getLat() {
        return lat;
    }

    public String getCollectOrNot() {
        return collectOrNot;
    }

    public String getNotInterested() {
        return notInterested;
    }

    public UserInfo getUserInfo() {
        return userInfo;
    }

    public EnterPrise getEnterPrise() {
        return enterPrise;
    }
}
